<template>
  <Container class="freight-list">
    <!-- <div class="container-header group" slot="header">
      <Input
        class="start"
        v-model.trim="list.form.keyword"
        placeholder="条码查询"
        clearable
        @on-enter="onSearchBtnClick">
      </Input>
      <Button type="primary" icon="ios-search" class="btn-search" @click="onSearchBtnClick"></Button>
    </div> -->
    <Tabs v-model="tab">
      <Button 
        slot="extra"
        type="primary"
        size="large"
        icon="ios-add"
        class="mr"
        @click="onBatchAdd">添加运费模板</Button>
      <TabPane label="运费设置" name="tab1">
        <Table
          :height="options.tableHeight"
          stripe
          :columns="list.columns"
          :data="list.data"
          @on-selection-change="onSelectChange"
          no-data-text="亲，没有找到相关记录哦！~"></Table>
        <Loader :status="list.status" @refresh="getData"></Loader>
      </TabPane>
    </Tabs>
    <EditItem ref="edit" @complete="getData"></EditItem>
  </Container>
</template>
<script>
import table from '@/table'
import CodeListData from './list/FreightListData'
import EditItem from './edit/EditItem.vue'
import { clearEmpty } from '@/util'
export default {
  name: 'operation/codeQuery/CodeQueryList',
  components: {
    EditItem
  },
  data() {
    return {
      ids: [],
      list: CodeListData,
      tab: 'tab1',
      // keyword: '',
      options: {
        tableHeight: 300
      },
      id: ''
    }
  },
  mounted() {
    this.getData()
    this.initTable()
    this.$bus.$on('onClickEnable', this.onClickEnable)
    this.$bus.$on('onClickView', this.onClickView)
    this.$bus.$on('onClickEdit', this.onClickEdit)
  },
  destroyed() {
    this.$bus.$off()
  },
  methods: {
    ...table,
    getData() {
      let param = {
        barcode:this.list.form.keyword
      }
      param = clearEmpty(param)
      this.list.status = 'loading'
      this.$ajaxPost('/freight/setting/listAll', param).then(data => {
        this.list.data = data
        this.list.status = 'pass'
        this.backTableTop()
      }).catch(() => {
        this.list.status = 'error'
      })
    },
    onClickEnable(row) {
      let text = '生效'
      if (row.isEnabled) {
        text = '失效'
      }
      this.$Modal.confirm({
        title: "提醒",
        content: `确认要${text}吗？`,
        onOk: () => {
          this.$ajaxPost("/freight/setting/enable", {id: row.id, enable: !row.isEnabled}).then(() => {
            this.$Notice.success({
              title: `设置${text}成功`
            });
            this.getData()
          });
        }
      });
    },
    onBatchAdd() {
      this.$refs.edit.open()
    },
    onClickView(row) {
      this.$refs.edit.open(row)
    }, 
    onClickEdit(row) {
      this.$refs.edit.openEdit(row, 'edit')
    }
	},
	
}
</script>